<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>采购订单相关的入库单记录</title>
    <script type="text/javascript">
      var newPurchaseOrderWin;
      var editPurchaseOrderWin;
      var purchaseOrderId;
      Ext.onReady(function(){
        //销售出库
        Ext.define('PurchaseEntry', {
          extend : 'Ext.data.Model',
          fields : [{
              name: 'id'
            },{
              name: 'purchase_order_number',
              mapping:'purchase_order.order_number'
            },{
              name: 'order_number'
            }, {
              name: 'action_date'
            }, {
              name: 'description'
            }, {
              name: 'employee_name',
              mapping:'employee.name'
            },{
              name: 'department_name',
              mapping:'department.name'
            }, {
              name: 'warehouse_name',
              mapping:'warehouse.name'
            }, {
              name: 'vendor_name',
              mapping:'vendor.name'
            }, {
              name: 'auditing_status'
            }, {
              name: 'deal_with_status'
            }, {
              name: 'created_at'
            }, {
              name: 'updated_at'
            }]
        });

        var entryForPurchaseDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'PurchaseEntry',
          proxy : {
            type : 'ajax',
            url : '/warehousing_entry/getWarehousingEntriesByPurchaseId',
            extraParams:{id:'<%=params[:id]%>'},
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          },
          autoLoad : true
        });

        //生成要订单的产品的Grid
        var entryForPurchaseGrid = Ext.create('Ext.grid.Panel', {
          title:'入库单列表',
          store: entryForPurchaseDS,
          columns : [{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '采购单号',
              dataIndex: 'purchase_order_number',
              width: 130
            },{
              header: '入库单号',
              dataIndex: 'order_number',
              width: 110
            },{
              header: '供应商',
              dataIndex: 'vendor_name',
              width: 150
            },{
              header: '到仓库',
              dataIndex: 'warehouse_name',
              width: 80
            },{
              header: '入库日期',
              dataIndex: 'action_date',
              renderer: Ext.util.Format.dateRenderer('Y-m-d'),width: 80
            },{
              header: '操作员',
              dataIndex: 'employee_name',
              width: 60
            },{
              header: '部门',
              dataIndex: 'department_name',
              width: 70
            },{
              header: '审批状态',
              dataIndex: 'auditing_status',
              renderer: auditingStatusRender,
              width: 60
            },{
              header: '订单状态',
              dataIndex: 'deal_with_status',
              renderer: dealWithStatusRender,
              width: 60
            },{
              header: '生成日期',
              dataIndex: 'created_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            },{
              header: '修改日期',
              dataIndex: 'updated_at',
              renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),width: 115
            }],
          loadMask: true,
          width: 980,
          height: 270,
          frame: true
        });

        entryForPurchaseGrid.on('itemdblclick', function(gridPanel, record,item,index,e,options){
          entryId = entryForPurchaseDS.getAt(index).get('id');
          var purchaseOrderNumber = entryForPurchaseDS.getAt(index).get('order_number');
          //entryForPurchaseDS.load();
          warehousingEntryDetailDS.removeAll();
          warehousingEntryDetailDS.load({params:{'id': entryId}});
          warehousingEntryDetailGrid.setTitle("入库单："+purchaseOrderNumber+"，的详细信息");
        });

        //--------------------------入库单详细，双击后可显示数据----------------
        Ext.define('PurchaseEntryDetail', {
          extend : 'Ext.data.Model',
          fields : [{
              name: 'id'
            },{
              name: 'product_name',
              mapping:'product.name'
            },{
              name: 'product_number',
              mapping:'product.number'
            },{
              name: 'product_spec',
              mapping:'product.spec'
            },{
              name: 'quantity'
            }, {
              name: 'unit_price'
            }, {
              name: 'amount'
            }, {
              name: 'is_suit',
              mapping:'product.is_suit',
              convert:function(value,record){
                if(value == "1"){
                  return "套装";
                }else if(value == "0"){
                  return "单品";
                }
              }
            }, {
              name: 'description'
            }]
        });

        var warehousingEntryDetailDS = Ext.create('Ext.data.Store', {
          //autoDestroy : true,
          model : 'PurchaseEntryDetail',
          proxy : {
            type : 'ajax',
            url : '/warehousing_entry/getWarehousingEntryDetailsById',
            reader : {
              type : 'json',
              root : 'root',
              totalProperty : 'totalProperty'// 数据集记录总数
            }
          }
        });
        
        //生成要订单的产品的Grid
        var warehousingEntryDetailGrid = Ext.create('Ext.grid.Panel', {
          title:'入库单详细列表',
          store: warehousingEntryDetailDS,
          columns : [{
              header: 'DB',
              dataIndex: 'id',
              width: 50
            },{
              header: '产品名称',
              dataIndex: 'product_name',
              width: 200
            },{
              header: '编号',dataIndex: 'product_number',width: 100
            },{
              header: '规格',
              dataIndex: 'product_spec',
              width: 80
            },{
              header: '数量',
              dataIndex: 'quantity',
              align: 'right',
              width: 80
            },{
              header: '单价',
              dataIndex: 'unit_price',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              align: 'right',
              width: 70
            },{
              header: '总价',
              dataIndex: 'amount',
              align: 'right',
              renderer: Ext.util.Format.numberRenderer('0,000.00'),
              width: 80
            },{
              header: '套装或单品',
              dataIndex: 'is_suit',
              width: 70
            },{
              header: '备注',
              dataIndex: 'description',
              width: 150
            }],
          loadMask: true,
          width: 980,
          height: 270,
          frame: true
          //title: '进货品种列表',
          //plain:true,
          //plugins: checkColumn,
        });
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
          width: 990,
          height: 590,
          frame:false,          
          layout: {type: 'table',columns:1},          
          items:[entryForPurchaseGrid,warehousingEntryDetailGrid]
        });
        workbenchPanel.render("entry_for_purchase_workbench_panel");
      })
    </script>
  </head>
  <body>
    <div id="entry_for_purchase_workbench_panel"></div>
  </body>
</html>